import logging
from time import sleep, time

import allure
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

from ding.LitemallPrac.page_objects.base_page import BasePage


class CommentPage(BasePage):
    _MENU_COMMENT=(By.XPATH,"// *[@ id='app'] / div / div[2] / section / div / div[2] / div[3] / table / tbody / tr[1] / td[7] / div / button[1]")
    _COMMENT_COM = (By.XPATH,"//div[@class='el-textarea el-input--mini']/textarea")
    _COMMET_YES = (By.XPATH,"//div[@class = 'dialog-footer']/button[@class = 'el-button el-button--primary el-button--mini']")
    _COMMENT_RESULT =(By.XPATH,"html/body/div[4]/div/h2")


    #回复
    with allure.step("商品评论回复"):
        def comment_launch(self):
            logging.info("点击回复")
            self.do_click(*self._MENU_COMMENT)
            sleep(2)
            # 定位到回复的弹框,输入回复信息
            # prompt属性的弹框
            logging.info("进入回复弹框")
            self.driver.switch_to.default_content()  # .send_keys("厉害")#*self._COMMENT_REQ
            logging.info("输入回复内容")
            self.do_send_keys("厉害", *self._COMMENT_COM)
            logging.info("确定")
            self.do_click(*self._COMMET_YES)
            # time.sleep(2)

            wait = WebDriverWait(self.driver, 1)
            self.driver.switch_to.default_content()
            element = wait.until(EC.visibility_of_element_located(self._COMMENT_RESULT))
            return element.text
            # alert.accept()

            # send_keys("厉害",*self._COMMENT_REQ)






